//
//  PurchaseManagerViewController.m
//  JackToolsBox
//
//  Created by Jack on 2020/1/19.
//  Copyright © 2020 Jack Xue. All rights reserved.
//

#import "PurchaseManagerViewController.h"
#import "JkReceiptManager.h"
@interface PurchaseManagerViewController ()
@property(strong,nonatomic)UITextField *jkkeyField;
@property(strong,nonatomic)UITextField *jkvalueField;
@end

@implementation PurchaseManagerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor lightGrayColor];
    
    self.jkkeyField = [[UITextField alloc]initWithFrame:CGRectMake(10, 140, 100, 30)];
    self.jkkeyField.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.jkkeyField];
    
    self.jkvalueField = [[UITextField alloc]initWithFrame:CGRectMake(150, 140, 100, 30)];
    self.jkvalueField.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.jkvalueField];
    
    NSArray *titleArray = @[@"新增",@"完成",@"查询"];
    for (NSInteger i = 0; i < titleArray.count; i++) {
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(50, 200 + 60 * i, 200, 50)];
        button.tag = 100 + i;
        [button setTitle:titleArray[i] forState:(UIControlStateNormal)];
        button.backgroundColor = [UIColor orangeColor];
        [button addTarget:self action:@selector(tapButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.view addSubview:button];
    }
    
}

-(void)tapButtonAction:(UIButton *)sender{
    NSInteger index = sender.tag - 100;
    if (index == 0) {
        [[JkReceiptManager manager]addUnfinishedPurchase:self.jkkeyField.text receipt:self.jkvalueField.text];
    }else if(index == 1){
        [[JkReceiptManager manager]finishPurchaseWithOrderId:self.jkkeyField.text];
    }else if(index == 2){
        NSArray *array = [[JkReceiptManager manager]checkUnfinishedPurchase];
        NSLog(@"%@",array);
    }
}



@end
